﻿package fui.FUIComponents{
	import flash.events.*;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.display.Bitmap;
	import fl.controls.*;
	import flash.net.URLRequest;
	
	import fl.containers.ScrollPane;
	import fui.FUIData.IDBClient;
	import fui.FUIData.DBClientV2;
	
	public class TemplateItem extends Sprite{
		private var _data:Object;
		private var _item:ScrollPane;
		var pictLdr:Loader;
		private var _img:ScrollPane;
		
		public function TemplateItem(itemData:Object, h:int,w:int, ypos:int)
		{
			y = ypos;
			_data = itemData;
			_item = new ScrollPane();
			_item.setSize(w, h);

			addChild(_item);
			pictLdr = new Loader();
			_img = new ScrollPane();
			
			_item.addChild(_img);
			_img.x = (w/3)*2;
			_img.setSize((w/3), (h - 8));
			_img.y = 1;
			for(var i = 0; i< _data.titles.length; i++)
			{
				var tx:Label = new Label();
				var txd:Label = new Label();
				tx.text =  _data.titles[i];
				tx.y = i*20;
				_item.addChild(tx);
				txd.text = _data.datas[i];
				txd.y = i*20;
				txd.x = 100;
				_item.addChild(txd);

			}
			getImage();
			
		}
		public function getImage():void
		{
			var pictURL:String = "http://b-o-g-o.com/"+_data.imagepath;
			trace("Image path:" + pictURL);
			var pictURLReq:URLRequest = new URLRequest(pictURL);
			pictLdr.load(pictURLReq);
			pictLdr.contentLoaderInfo.addEventListener( Event.INIT , loaded)

		}
		private function loaded(event:Event):void {
			//var targetLoader:Loader = Loader(event.target.loader);
			var image:Bitmap = (Bitmap)(event.target.content);

			image.height = _item.height - 8;
			image.width = _item.width/3;

			//targetLoader.width = _item.width/3;
			//targetLoader.scaleY = targetLoader.scaleX;
			trace("Loaded!!");
			_img.addChild(image);
}
	}
}